import { EditOrReadOnlyContext } from '@ant-design/pro-form/es/BaseForm/EditOrReadOnlyContext';
import { ProFormFieldItemProps } from '@ant-design/pro-form/es/typing';
import { useContext } from 'react';

/**
 * 获取是否只读
 */
export default function useReadOnly(
  proFormItemProps: ProFormFieldItemProps<any>,
) {
  const modeContext = useContext(EditOrReadOnlyContext);
  return (
    proFormItemProps.readonly ||
    proFormItemProps.fieldProps?.readonly ||
    proFormItemProps.fieldProps?.readOnly ||
    modeContext.mode === 'read'
  );
}
